package com.example.test10_1;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button ok = (Button) findViewById(R.id.ok);
        ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                EditText username = (EditText) findViewById(R.id.username);//获得输入用户名的控件
                EditText password = (EditText) findViewById(R.id.password);//获得输入密码的控件
                Intent intent = new Intent();//创建Intent对象
                //封装用户名信息
                intent.putExtra("USERNAME",username.getText().toString());
                intent.putExtra("PASSWORD",password.getText().toString());
                intent.setClass(MainActivity.this,SecondActivity.class);//指定传递对象
                startActivity(intent);//将Intent传递给Activity
            }
        });
    }
}